package spe.ui.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;

import spe.model.spem.SPEMElement;

public class OpenSPEItemAction extends Action
{
	private IWorkbenchPage page;
	private ISelectionProvider selectionProvider;
	private Object item;
	
	public OpenSPEItemAction(IWorkbenchPage p, ISelectionProvider sp)
	{
		super("Open");
		//setText("Open");
		page = p;
		selectionProvider = sp;
	}
	
	@Override
	public boolean isEnabled()
	{
		ISelection selection = selectionProvider.getSelection();
		if(!selection.isEmpty())
		{
			System.out.println(String.format("[OpenSPEItemAction] isEnabled"));
			IStructuredSelection ss = (IStructuredSelection)selection;
			if(ss.size() == 1 && SPEMElement.class.isInstance(ss.getFirstElement()))
			{
				item = (SPEMElement)ss.getFirstElement();
				return true;
			}
		}
		return false;
	}
	
}
